<%--
  @author Tharanga Punchihewa
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">

    /*$(function() {
     var mode = document.getElementById("page_mode").value;
     if (mode == 7) {
     var fieldIds = new Array('organizationNameEn', 'natureOfInterestId', 'permissionMethodId');
     enableFields(fieldIds);
     }
     });*/

    $(function() {
        var pageMode = document.getElementById("page_mode").value;
        var editMode = document.getElementById("edit_mode").value;
        //alert("pageMode="+pageMode);
        //alert("editMode="+editMode);
        if (pageMode == 7 || editMode == 1) {
            //approve and edit
            if (pageMode == 7) {
                //Approve
                disableWithOutComment();
                $('#rejectComment').hide();
            } else {
                //Edit
                disableComment();
                var commentTxt = document.getElementById("comment").value;
                if (commentTxt.length > 0) {
                    $('#rejectComment').show();
                } else {
                    $('#rejectComment').hide();
                }

            }
        } else {
            $('#rejectComment').hide();
        }
    });

    function disableComment() {
        var fieldIds = new Array('comment');
        enableFields(fieldIds);
    }
    function disableWithOutComment() {
        var fieldIds = new Array('referenceNumberId', 'natureOfInterestId', 'permissionMethodId', 'conditionId',
                'validPeriodId', 'isAlienated0', 'isAlienated1');
        enableFields(fieldIds);
    }

    function validateReject() {
        $('#rejectComment').show();
        /* var comment = document.getElementById("comment").value;
         alert(comment);*/
        $('#comment').rules("add", {
            required:true,
            messages:{
                required: " Please Enter a Reject Comment " }
        });
    }


</script>


<script type="text/javascript">
    $(document).ready(function() {
        var dO = new Date();
        var d = dO.getDate();
        var m = dO.getMonth();
        var y = dO.getFullYear();
        var today = d + "/" + m + "/" + y;
        /*$('#dueDateId').DatePicker({
         format:'m/d/Y',
         date:today,
         current: today,
         starts: 1,
         position: 'right',
         onBeforeShow: function() {
         $('#dueDateId').DatePickerSetDate(today, true);
         },
         onChange: function(formated, dates) {
         $('#dueDateId').val(formated);
         }
         });*/

        var pls_enter_the_reference_number = "<br>" + document.getElementById("pls_enter_the_reference_number").value;
        var pls_enter_the_nature_of_the_interest = "<br>" + document.getElementById("pls_enter_the_nature_of_the_interest").value;

        $("#add-interest-from").validate({
            rules: {
                referenceNumberId: {
                    required:true
                },
                natureOfInterestId: {
                    required:true
                }
            },
            messages: {
                referenceNumberId:pls_enter_the_reference_number,
                natureOfInterestId:pls_enter_the_nature_of_the_interest
            }
        });
    });
</script>

<div id="org-info-module-home-title" class="module-home-title">
    <%--<s:a href="landInterests.do"><img src="${pageContext.request.contextPath}/images/company-profile.png"
                                             alt="Organizational Information"><span>Organizational Information</span></s:a>--%>
    <s:a href="home.do"><img src="${pageContext.request.contextPath}/images/home.png"
                                    alt="Organizational Information"><span><s:label
            value="%{getText('manage_organization_interest.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>

    <s:if test="pageMode ==7">
        <%--ORPII Approve or Reject Interest--%>
        <s:a href="approveGOInterestInformationList.do"><img src="${pageContext.request.contextPath}/images/accept.png"
                                                             alt="Organizational Information"><span><s:label
                value="%{getText('go_interest_info_approval.label')}"/></span></s:a>
    </s:if>
    <s:elseif test="editMode ==1">
        <%--ORMOI Edit Interest--%>
        <s:a href="#"><img src="${pageContext.request.contextPath}/images/company-profile.png"
                           alt="Organizational Information"><span><s:label
                value="%{getText('edit_go_interest_information.label')}"/></span></s:a>
    </s:elseif>
    <s:else>
        <%--ORMOI ADD Interest--%>
        <s:a href="#"><img src="${pageContext.request.contextPath}/images/company-profile.png"
                           alt="Organizational Information"><span><s:label
                value="%{getText('add_go_interest_information.label')}"/></span></s:a>

    </s:else>

</div>
<s:if test="hasActionErrors() || hasActionMessages()">
    <div id="message-box" class="message-box">
        <div class="action-msg"><s:actionmessage/></div>
        <div class="action-err"><s:actionerror/></div>
    </div>
</s:if>
<div id="add-organization-from-outer" class="form-outer">
    <div class="page-title">
        <h2><s:label value="%{getText('organization_interest_information.label')}"/></h2>
    </div>
    <s:form method="POST" id="add-interest-from" enctype="multipart/form-data">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('reference_number.label')}" cssClass="mandatory-field"/></td>
                <td colspan="2"><s:textfield name="goInterestInformation.referenceNumber"
                                             id="referenceNumberId"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('nature_of_interest.label')}" cssClass="mandatory-field"/></td>
                <td colspan="2"><s:textarea cssClass="width-500-px" name="goInterestInformation.natureOfInterest"
                                            id="natureOfInterestId"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('permission_method.label')}"/></td>
                <td colspan="2"><s:textarea cssClass="width-500-px" name="goInterestInformation.permissionMethod"
                                            id="permissionMethodId"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('condition.label')}"/></td>
                <td colspan="2"><s:textarea cssClass="width-500-px" name="goInterestInformation.conditionOfInterest"
                                            id="conditionId"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('valid_period.label')}"/></td>
                <td colspan="2"><s:textarea cssClass="width-500-px" name="goInterestInformation.validPeriod"
                                            id="validPeriodId"/></td>
            </tr>

            <tr>
                <td><s:label value="%{getText('isAlienated.label')}"/></td>
                <td colspan="2"><s:radio id="isAlienated" name="goInterestInformation.alienated"
                                         list="#@java.util.HashMap@{'0':getText('yes.label'),'1':getText('no.label')}"/></td>
            </tr>
                <%--<table>
                    <tr>
                        <td align="left-align"><s:include value="../documentUpload.jsp"/></td>
                    </tr>
                </table>--%>
            <s:if test="pageMode ==7">
                <table>
                    <s:include value="mapGO.jsp"/>
                </table>
            </s:if>


            <table id="rejectComment" class="width-100">
                <tr>
                    <td><s:label value="%{getText('comments.label')}"/></td>
                    <td colspan="3"><s:textarea id="comment" name="goInterestInformation.comment"
                                                cssClass="width-595-px"/></td>
                </tr>
            </table>

            <tr>
                <td></td>
                <td colspan="2">
                    <s:hidden id="edit_mode" name="editMode"/>
                    <s:if test="editMode ==1">
                        <s:submit value="%{getText('edit.label')}" action="addGOInterestInformation"/>
                        <s:hidden name="goInterestInformation.id"/>
                    </s:if>
                    <s:elseif test="pageMode !=7">
                        <s:submit value="%{getText('save.label')} " action="addGOInterestInformation"/>
                    </s:elseif>
                    <s:if test="pageMode ==7">
                        <s:submit value="%{getText('approve_button.label')} " action="approveInterestInfo"/>
                        <s:submit value="%{getText('reject_button.label')} " action="rejectInterestInfo"
                                  onclick="validateReject()"/>
                        <s:hidden name="goInterestInformation.id"/>
                    </s:if>
                        <%--<s:submit value="Exit" align="center" action="goInterestsHome"/>--%>
                </td>
            </tr>
        </table>
    </s:form>


</div>
<s:hidden id="page_mode" name="pageMode"/>
<s:hidden id="pls_enter_the_reference_number" value="%{getText('pls_enter_the_reference_number.label')}"/>
<s:hidden id="pls_enter_the_nature_of_the_interest" value="%{getText('pls_enter_the_nature_of_the_interest.label')}"/>
